package com.ywgt.collection;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListSafeTest {
    public static void main(String[] args) {

        //线程不安全List<String> list=new ArrayList<>();
        //解决方案1：List<String> list=new Vector<>();
        //解决方案2：List list= Collections.synchronizedList(new ArrayList<String>());
        //解决方案3:List list= new CopyOnWriteArrayList();JUC
        List list= new CopyOnWriteArrayList();
        for(int i=0;i<10;i++){
            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(5));
                System.out.println(list);
            },String.valueOf(i)).start();
        }
    }
}
